//
//  ReceiptTableViewCell.m
//  BeautyPicture
//
//  Created by LiuNa on 16/2/25.
//  Copyright © 2016年 szb. All rights reserved.
//

#import "ReceiptTableViewCell.h"
#import "BPImageTool.h"
#import "indentModel.h"
#import "BPImageTool.h"
#import "MJExtension.h"


@implementation ReceiptTableViewCell
@synthesize delegate;


+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"receipt";
    //    childBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    //if (!cell) {
    ReceiptTableViewCell *cell = [[ReceiptTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    //}
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        CGFloat imageY = 15.0f;
        CGFloat imageW = 140.0 - imageY * 2.0f;
        CGFloat imageX = 10.0f;
        _productImage = [[UIImageView alloc] initWithFrame:CGRectMake(imageX, imageY, imageW, imageW)];
        _productImage.contentMode = UIViewContentModeScaleAspectFit;
        [_productImage.layer setBorderColor:[BPGlobaBGColor CGColor]];
        [_productImage.layer setBorderWidth:0.7];
        [self addSubview:_productImage];
        
        CGFloat labelX = CGRectGetMaxX(_productImage.frame) + 10.0f;
        CGFloat labelW = 200.0f;
        CGFloat labelY = imageY + 10.0f;
        _Name = [[UILabel alloc] initWithFrame:CGRectMake(labelX, labelY, labelW, 16.0f)];
        _Name.font = [UIFont systemFontOfSize:15.0f];
        [self addSubview:_Name];
        
        _Standard = [[UILabel alloc] initWithFrame:CGRectMake(labelX,labelY + (_Name.height + 7.0f), labelW, 13.0f)];
        self.Standard.alpha = 0.3;
        _Standard.font = [UIFont systemFontOfSize:13.0f];
        [self addSubview:_Standard];
        
        CGFloat timeY = CGRectGetMaxY(_Standard.frame) + 7;
        _Time = [[UILabel alloc] initWithFrame:CGRectMake(labelX, timeY, labelW, 13.0f)];
        self.Time.alpha = 0.5;
        _Time.font = [UIFont systemFontOfSize:13.0f];
        [self addSubview:_Time];
        
        CGFloat btnY = CGRectGetMaxY(_Time.frame) + 7;
        //        _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
        //        _rightButton.frame = CGRectMake(labelX, btnY + 20, 75.0, 25.0);
        //        _rightButton.backgroundColor = BPGlobaThemeColor;
        //        [self setupButton:_rightButton];
        
        //        CGFloat btnX = CGRectGetMaxX(_rightButton.frame)+10.0f;
        //        _leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        //        _leftBtn.frame = CGRectMake(btnX, btnY + 20, 75.0, 25.0f);
        //        _leftBtn.backgroundColor = pinkBtnColor;
        //        [self setupButton:_leftBtn];
        
        
        self.xianJia = [[UILabel alloc] initWithFrame:CGRectMake(labelX, btnY + 10, 80, 20)];
        self.xianJia.textColor = [UIColor redColor];
        [self addSubview:self.xianJia];
        
        
        
        
        self.yuanJia = [[UILabel alloc] initWithFrame:CGRectMake(labelX + 100, btnY + 10, 80, 20)];
        self.yuanJia.textColor = [UIColor grayColor];
        self.yuanJia.font = [UIFont systemFontOfSize:13];
        [self addSubview:self.yuanJia];
        
        NSString *string = @"原价:";
        NSString *Yuan = [NSString stringWithFormat:@"%@%@", string, @"100.0"];
        NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:13], NSStrikethroughStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle]};
        NSAttributedString *attString = [[NSAttributedString alloc] initWithString:Yuan attributes:dic];
        self.yuanJia.attributedText = attString;
        
        
        
        self.backgroundColor = [UIColor clearColor];
        self.selectedBackgroundView = [[UIImageView alloc] init];
        
        BPLineView *line = [[BPLineView alloc] initWithFrame:CGRectMake(0, 140.0, BPScreenW, 0.7)];
        [self addSubview:line];
        
        
        /** 签收日期 */
        CGFloat LabX = 5.0;
        CGFloat LabY = 145.0f;
        CGFloat LabW = 60.0;
        CGFloat LabH = 20.0f;
        self.qianshou = [[UILabel alloc] initWithFrame:CGRectMake(LabX, LabY, LabW, LabH)];
//        self.qianshou.text = @"签收日期:";
        self.qianshou.font = [UIFont systemFontOfSize:13];
        self.qianshou.textColor = [UIColor blackColor];
        self.qianshou.alpha = 0.5;
        [self addSubview:self.qianshou];
        
        CGFloat LabWW = self.frame.size.width - (LabX + LabW + 5.0f);
        self.day = [[UILabel alloc] initWithFrame:CGRectMake(LabX + LabW + 5.0f, LabY, LabWW, LabH)];
        self.day.font = [UIFont systemFontOfSize:13];
        self.day.textColor = [UIColor blackColor];
        self.day.alpha = 0.5;
        [self addSubview:self.day];
        
        self.shouHuoDay = [[UILabel alloc] initWithFrame:CGRectMake(LabX + LabW + 5.0f, LabY, LabWW, LabH)];
        self.shouHuoDay.font = [UIFont systemFontOfSize:13];
        self.shouHuoDay.textColor = [UIColor blackColor];
        self.shouHuoDay.alpha = 0.5;
        [self addSubview:self.shouHuoDay];
        
        /** 承运来源 */
        self.laiyuan = [[UILabel alloc] initWithFrame:CGRectMake(5, LabY + 25, LabW, LabH)];
        self.laiyuan.text = @"承运来源:";
        self.laiyuan.font = [UIFont systemFontOfSize:13];
        self.laiyuan.textColor = [UIColor blackColor];
        self.laiyuan.alpha = 0.5;
        [self addSubview:self.laiyuan];
        
        self.kuaidi = [[UILabel alloc] initWithFrame:CGRectMake(LabX + LabW + 5.0f, LabY + 25, LabWW, LabH)];
        self.kuaidi.font = [UIFont systemFontOfSize:13];
        self.kuaidi.alpha = 0.5;
        self.kuaidi.textColor = [UIColor blackColor];
        [self addSubview:self.kuaidi];
        
        
         /** 快递单号 */
        self.bianhao = [[UILabel alloc] initWithFrame:CGRectMake(LabX, LabY + 50, LabW, LabH)];
        self.bianhao.text = @"快递单号:";
        self.bianhao.font = [UIFont systemFontOfSize:13];
        self.bianhao.textColor = [UIColor blackColor];
        self.bianhao.alpha = 0.5;
        [self addSubview:self.bianhao];
        
        self.danhao = [[UILabel alloc] initWithFrame:CGRectMake(LabX + LabW + 5.0f, LabY + 50.0f, LabWW, LabH)];
        self.danhao.textColor = [UIColor blackColor];
        self.danhao.alpha = 0.5;
        self.danhao.font = [UIFont systemFontOfSize:13];
        [self addSubview:self.danhao];
    }
    return self;
}

- (void)setupButton:(UIButton *)button
{
    [button.layer setMasksToBounds:YES];
    [button.layer setCornerRadius:10.0f];
    button.titleEdgeInsets = UIEdgeInsetsMake(0, 4.0f, 0, 0);
    button.imageEdgeInsets = UIEdgeInsetsMake(0, -3.0, 0, 0);
    button.titleLabel.font = [UIFont boldSystemFontOfSize:13.0f];
    [self addSubview:button];
    
}

- (void)setUpCell:(productModel *)model
{
    //self.yuanJia.text = @"原价:100";
    // 现价
    NSString *strM = @"¥";
    self.xianJia.text = [NSString stringWithFormat:@"%@%@", strM, model.status];
    
  
    
    self.Name.text = [NSString stringWithFormat:@"%@-%@",model.title,model.category];
    self.Standard.text = [NSString stringWithFormat:@"规格:%@   %@页",model.page_standard,model.pagetotal];
    if (model.create_time == nil) {
        NSArray *array = [model.makeDate componentsSeparatedByString:@" "];
        model.create_time = array[0];
    }
    
    self.Time.text = model.create_time;
    if ([model.picture isKindOfClass:[NSNull class]]) {
        model.picture = nil;
    }
    
    [BPImageTool setUpUIImageView:self.productImage addNsstringUrl:model.picture];
    //    [self setupstateButtonLabel:@"删除" buttonImage:@"deleBtnImage" addbutton:_leftBtn];
    //    [self.leftBtn addTarget:self action:@selector(shanchu) forControlEvents:UIControlEventTouchUpInside];
    
    //    if ([model.status isEqualToString:@"3"]) {
    //        [self setupstateButtonLabel:@"继续编辑" buttonImage:@"continueEditBtnImage" addbutton:_rightButton];
    //        [self.rightButton addTarget:self action:@selector(jixubianji) forControlEvents:UIControlEventTouchUpInside];
    //    }else if([model.status isEqualToString:@"2"] || [model.status isEqualToString:@"1"]){
    //        [self setupstateButtonLabel:@"查看详情" buttonImage:@"detailBtnImage" addbutton:_rightButton];
    //        [self.rightButton addTarget:self action:@selector(xiangqing) forControlEvents:UIControlEventTouchUpInside];
    //    }else if([model.status isEqualToString:@"0"]){
    //        [self setupstateButtonLabel:@"继续编辑" buttonImage:@"continueEditBtnImage" addbutton:_rightButton];
    //        [self.rightButton addTarget:self action:@selector(jixubianji) forControlEvents:UIControlEventTouchUpInside];
    //    }
}

- (void)setUpShareCell:(shareModel *)model
{
    self.Name.text = [NSString stringWithFormat:@"%@-%@",model.title,model.category];
    self.Standard.text = [NSString stringWithFormat:@"规格:%@   %@页",model.page_standard,model.pagetotal];
    self.Time.text = model.create_time;
    if ([model.picture isKindOfClass:[NSNull class]]) {
        model.picture = nil;
    }
    [BPImageTool setUpUIImageView:self.productImage addNsstringUrl:model.picture];
    [self setupstateButtonLabel:@"删除" buttonImage:@"deleBtnImage" addbutton:_leftBtn];
    [self.leftBtn addTarget:self action:@selector(shanchu) forControlEvents:UIControlEventTouchUpInside];
    if([model.isshare isEqualToString:@"0"]){
        [self setupstateButtonLabel:@"我要分享" buttonImage:@"shareBtnImage" addbutton:_rightButton];
        [self.rightButton addTarget:self action:@selector(fenxiang) forControlEvents:UIControlEventTouchUpInside];
    }else if([model.isshare isEqualToString:@"1"]){
        [self setupstateButtonLabel:@"再次分享" buttonImage:@"shareBtnImage" addbutton:_rightButton];
        [self.rightButton addTarget:self action:@selector(fenxiang2) forControlEvents:UIControlEventTouchUpInside];
    }else{
        BPLog(@"error");
    }
}
- (void)setUpCellTow:(indentModel *)model{

    // 原价
    NSString *string = @"原价:";
    NSString *Yuan = [NSString stringWithFormat:@"%@%@", string, model.oprice];
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:13], NSStrikethroughStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle]};
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:Yuan attributes:dic];
    self.yuanJia.attributedText = attString;
    
    self.shouHuoDay.text = model.send_time;
    self.kuaidi.text = model.tool;
    self.danhao.text = model.toolid;
    
    
    NSString *strM = @"¥";
    self.xianJia.text = [NSString stringWithFormat:@"%@%@", strM, model.price];
    self.Standard.text = [NSString stringWithFormat:@"规格:%@   %@页",model.page_standard,model.pagetotal];
    
    self.Name.text = [NSString stringWithFormat:@"%@--%@",model.name,model.category];
    //self.Standard.text = model.orderid;
    //    self.Time.attributedText = content;
    
    // self.Time 是 订单号.
    self.Time.text = model.orderid;
    self.Time.alpha = 0.5;
    self.Time.textColor = BPGlobaThemeColor;

    
    
    NSString *str = [NSString stringWithFormat:@"￥%@",model.total];
    NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:str];
    NSRange contentRange = {1,[content length] -1};
    [content addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.0f] range:contentRange];
//    self.Name.text = model.orderid;
//    self.Standard.text = [NSString stringWithFormat:@"%@--%@",model.name,model.category];
//    self.Time.attributedText = content;
//    self.Time.alpha = 0.5;
//    self.Time.textColor = BPGlobaThemeColor;
    if ([model.pic isKindOfClass:[NSNull class]]) {
        model.pic = nil;
    }
    [BPImageTool setUpUIImageView:self.productImage addNsstringUrl:model.pic];
    
    if ([model.status isEqualToString:@"100"]) {
        [self setupstateButtonLabel:@"立即支付" buttonImage:@"payBtnImage" addbutton:_leftBtn];
        [self.leftBtn addTarget:self action:@selector(zhifu) forControlEvents:UIControlEventTouchUpInside];
        
        [self setupstateButtonLabel:@"删除" buttonImage:@"deleBtnImage" addbutton:_rightButton];
        [self.rightButton addTarget:self action:@selector(shanchu) forControlEvents:UIControlEventTouchUpInside];
        
    }else if([model.status isEqualToString:@"200"]||[model.status isEqualToString:@"300"]||[model.status isEqualToString:@"400"]){
        [self setupstateButtonLabel:@"查看物流" buttonImage:@"expressBtnImage" addbutton:_rightButton];
        [self.rightButton addTarget:self action:@selector(wuliu) forControlEvents:UIControlEventTouchUpInside];
        
        [self setupstateButtonLabel:@"确认收货" buttonImage:@"extendBtnImage" addbutton:_leftBtn];
        [self.leftBtn addTarget:self action:@selector(shouhuo) forControlEvents:UIControlEventTouchUpInside];
    }else if([model.status isEqualToString:@"500"]){
        self.rightButton.hidden = YES;
        if ([model.isshare intValue] == 0) {
            //可以去晒单
            [self setupstateButtonLabel:@"马上晒单" buttonImage:@"expressBtnImage" addbutton:_leftBtn];
            [self.leftBtn addTarget:self action:@selector(shaidan) forControlEvents:UIControlEventTouchUpInside];
        }else{
            //已经晒过单
            [self setupstateButtonLabel:@"删除" buttonImage:@"deleBtnImage" addbutton:_leftBtn];
            [self.leftBtn addTarget:self action:@selector(shanchu) forControlEvents:UIControlEventTouchUpInside];
        }
    }

}


- (void)setUpCell22:(indentModel *)model
{
    
    
    // 原价
    NSString *string = @"原价:";
    NSString *Yuan = [NSString stringWithFormat:@"%@%@", string, model.oprice];
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:13], NSStrikethroughStyleAttributeName:[NSNumber numberWithInt:NSUnderlineStyleSingle]};
    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:Yuan attributes:dic];
    self.yuanJia.attributedText = attString;
    
    
    self.day.text = model.end_time;
    self.kuaidi.text = model.tool;
    self.danhao.text = model.toolid;
    NSString *strM = @"¥";
    self.xianJia.text = [NSString stringWithFormat:@"%@%@", strM, model.price];
    self.Standard.text = [NSString stringWithFormat:@"规格:%@   %@页",model.page_standard,model.pagetotal];
    
    
    self.Name.text = [NSString stringWithFormat:@"%@--%@",model.name,model.category];
    //self.Standard.text = model.orderid;
    //    self.Time.attributedText = content;
    
    // self.Time 是 订单号.
    self.Time.text = model.orderid;
    self.Time.alpha = 0.5;
    self.Time.textColor = BPGlobaThemeColor;

    
    NSString *str = [NSString stringWithFormat:@"￥%@",model.total];
    NSMutableAttributedString *content = [[NSMutableAttributedString alloc]initWithString:str];
    NSRange contentRange = {1,[content length] -1};
    [content addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.0f] range:contentRange];
//    self.Name.text = model.orderid;
//    self.Standard.text = [NSString stringWithFormat:@"%@--%@",model.name,model.category];
//    self.Time.attributedText = content;
    self.Time.text = model.orderid;
    self.Time.alpha = 0.5;
    self.Time.textColor = BPGlobaThemeColor;
    if ([model.pic isKindOfClass:[NSNull class]]) {
        model.pic = nil;
    }
    [BPImageTool setUpUIImageView:self.productImage addNsstringUrl:model.pic];
    
    if ([model.status isEqualToString:@"100"]) {
        [self setupstateButtonLabel:@"立即支付" buttonImage:@"payBtnImage" addbutton:_leftBtn];
        [self.leftBtn addTarget:self action:@selector(zhifu) forControlEvents:UIControlEventTouchUpInside];
        
        [self setupstateButtonLabel:@"删除" buttonImage:@"deleBtnImage" addbutton:_rightButton];
        [self.rightButton addTarget:self action:@selector(shanchu) forControlEvents:UIControlEventTouchUpInside];
        
    }else if([model.status isEqualToString:@"200"]||[model.status isEqualToString:@"300"]||[model.status isEqualToString:@"400"]){
        [self setupstateButtonLabel:@"查看物流" buttonImage:@"expressBtnImage" addbutton:_rightButton];
        [self.rightButton addTarget:self action:@selector(wuliu) forControlEvents:UIControlEventTouchUpInside];
        
        [self setupstateButtonLabel:@"确认收货" buttonImage:@"extendBtnImage" addbutton:_leftBtn];
        [self.leftBtn addTarget:self action:@selector(shouhuo) forControlEvents:UIControlEventTouchUpInside];
    }else if([model.status isEqualToString:@"500"]){
        self.rightButton.hidden = YES;
        if ([model.isshare intValue] == 0) {
            //可以去晒单
            [self setupstateButtonLabel:@"马上晒单" buttonImage:@"expressBtnImage" addbutton:_leftBtn];
            [self.leftBtn addTarget:self action:@selector(shaidan) forControlEvents:UIControlEventTouchUpInside];
        }else{
            //已经晒过单
            [self setupstateButtonLabel:@"删除" buttonImage:@"deleBtnImage" addbutton:_leftBtn];
            [self.leftBtn addTarget:self action:@selector(shanchu) forControlEvents:UIControlEventTouchUpInside];
        }
    }
}


- (void)setupstateButtonLabel:(NSString *)labelText buttonImage:(NSString *)imageText addbutton:(UIButton *)button
{
    [button setTitle:labelText forState:UIControlStateNormal];
    
    [button setImage:[UIImage imageNamed:imageText] forState:UIControlStateNormal];
}

- (void)jixubianji
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(continueDIYReC:)]) {
        [self.delegate continueDIYReC:self];
    }
}

- (void)yinshua
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(goToPrintReC:)]) {
        [self.delegate goToPrintReC:self];
    }
}

- (void)xiangqing
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(lookDetailReC:)]) {
        [self.delegate lookDetailReC:self];
    }
}

- (void)fenxiang
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(shareProductReC:)]) {
        [self.delegate shareProductReC:self];
    }
}

- (void)fenxiang2
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(shareAgainReC:)]) {
        [self.delegate shareAgainReC:self];
    }
}

- (void)shanchu
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(shanchuCellReC:)]) {
        [self.delegate shanchuCellReC:self];
    }
}

- (void)zhifu
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(quicklyPayManyReC:)]) {
        [self.delegate quicklyPayManyReC:self];
    }
}

- (void)wuliu
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(lookWUliuReC:)]) {
        [self.delegate lookWUliuReC:self];
    }
}

- (void)dindan
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(lookDinDanReC:)]) {
        [self.delegate lookDinDanReC:self];
    }
}

- (void)shaidan
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(quickShaidanReC:)]) {
        [self.delegate quickShaidanReC:self];
    }
}

- (void)shouhuo
{
    if (delegate !=nil && [delegate respondsToSelector:@selector(querenGoodsReC:)]) {
        [self.delegate querenGoodsReC:self];
    }
}





- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
